<!DOCTYPE html>
<!--

musical-sequences/index.html

Musical Sequences implementation

Copyright (C) 2012, Chris Allert, All rights reserved.

This program is free software; you can redistribute it and/or modify it under 
the terms of the GNU General Public License as published by the Free Software 
Foundation; either version 3 of the License, or (at your option) any later 
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY 
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple 
Place, Suite 330, Boston, MA 02111-1307 USA

The latest version of this file can be downloaded from
http://thought-patches.sourceforge.net/

-->
<html>
<head>
<title>musical sequences</title>
<script src="middle_c.js"></script>
<script src="middle_d.js"></script>
<script>
	function get_output() {
		return document.getElementById("output_text");
	}

	function get_value(s) {
		return 1 * document.getElementById(s).value;
	}

	function error_log(s) {
		var o = get_output();
		o.value = "error: " + s;
		return false;
	}

	function check_terms(a, b) {
		if (isNaN(a)) { 
			return error_log("term a is not a number");
		} 
		if (isNaN(b)) { 
			return error_log("term b is not a number");
			return false;
		}
		if (a > b) {
			return error_log(a + " > " + b);
			return false;
		}
		return true;
	}

	function show_middle_c() {
		show_sequence(middle_c_get_distance);
	}

	function show_middle_d() {
		show_sequence(middle_d_get_distance);
	}

	function show_sequence(f) {
		var o = get_output();
		var t = "empty";
		var n;
		var i_a = get_value("term_a");
		var i_b = get_value("term_b");
		if (! check_terms(i_a, i_b)) { return; }
		var s = "sequence from " + i_a + " to " + i_b + " is:\n"; 
		var i = 0;
		for (i = i_a; i <= i_b; ++i) {
			n = f(i);
			if (!isNaN(t)) {
				s += (
					(1.01 > (n - t)) ?
					"S" : "L"
					) + "\n";
			}
			s += (i + ": " + f(i) + "\n");
			t = n;
		}
		o.value = s;
	}

</script>
</head>
<body>
	from: <input name="term_a" id="term_a" value="0" /><br />
	to: <input name="term_b" id="term_b" value="1" /><br />
	<button id="middle_c" onclick="show_middle_c()">middle c</button>
	<button id="middle_d" onclick="show_middle_d()">middle d</button>
	<br />
	<textarea id="output_text" name="output_text" rows="30" cols="80"></textarea>
</body>

